import sys

while True:
    n = input('请输入一个4位整数:').strip()
    if 4 != len(n):
        print(flush=True)
        print('输入有误，请重新输入。', flush=True, file=sys.stderr)
    else:
        print('您输入的是:', n)
        break

int_n = n
if not(isinstance(int_n, int)):
    print(int_n, '不是整形', sep='')
    int_n = int(int_n);
    print('将', n, '转成整形后是', int_n, sep='')

if 0 == int_n % 2:
    w = '偶数'
else:
    w = '奇数'
print(int_n, '是', w, sep='')


def is_product_of(n, m):
    if 0 == n % m:
        return True
    else:
        return False


arr = [3, 7, 13]
for i in arr:
    if is_product_of(int_n, i):
        w = '是'
    else:
        w = '不是'
    print(int_n, w, i, '的倍数', sep='')


def get_digit_of(n, m):
    n //= (10 ** (m - 1));
    return n % 10


for i, j in enumerate(['个', '十', '百', '千']):
    print(j, '位数是', get_digit_of(int_n, i + 1), sep='')

# 判断后三位是否为水仙花数
sum = 0
num = 0
for i in range(0, 3):
    d = get_digit_of(int_n, i + 1)
    sum += d ** 3
    num += d * (10 ** i)
if sum == num:
    w = '是'
else:
    w = '不是'
print(int_n, w, '水仙花数', sep='')

# 把number的类型再转为字符形，并输出其类型
str_n = str(int_n)
print('目前', str_n, '的类型是', sep='', end='')
print(type(str_n))

# 用序列的合适方法输出对应的“个位数、十位数、百位数、千位数”
for i, j in enumerate(['个', '十', '百', '千']):
    print(j, '位数是', str_n[i], sep='')

segm = """\
Responsive interactives (between 320px-800px width) with live results that update automatically """"""\
(publish using embed code supplied). First updates expected after first polls close on the East """"""\
Coast at 19:00 local time November 4."""

print('将.都换成空格后是:', segm.replace('.', ' '))
print('全部大写是:', segm.upper())
print('全部小写是:', segm.lower())

print('挑选输出大写字母: ')
for a in segm:
    if a.isupper():
        print(a, end=', ')
print()

print('挑选输出其中数字')
for a in segm:
    if a.isdigit():
        print(a, end=', ')
print()

print('如果November是一个敏感词汇，将其替换成**: ', segm.replace('November', '**'))

prompt = """\
1 - all upper
2 - all lower
3 - pick upper letter
4 - pick digits
5 - alternate"""
while True:
    print(prompt)
    n = int(input('Your choice: ').strip())
    if 1 == n:
        print(segm.upper())
    elif 2 == n:
        print(segm.lower())
    elif 3 == n:
        for a in segm:
            if a.isupper():
                print(a, end=', ')
        print()
    elif 4 == n:
        for a in segm:
            if a.isdigit():
                print(a, end=', ')
        print()
    elif 5 == n:
        tgt = str(input('What to replace? : '))
        print(segm.replace(tgt, '**'))
    else:
        print('Exit')
        break
